package com.zzz.poker.controller;

import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.zzz.poker.entity.Room;
import com.zzz.share.common.core.exception.BusinessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @BelongsProject: share
 * @BelongsPackage: com.zzz.poker.controller
 * @Author: zwq
 * @CreateTime: 2025-05-07  19:54
 * @Description: 斗地主控制层
 * @Version: 1.0
 */
@RestController
@RequestMapping("/ddz")
public class DdzController {

    @Value("${server.port}")
    private String port;


    @GetMapping("/testRedis")
    public void testRedis() {
        Room room = new Room();
        room.setId("1");
        Room one = Db.getOne(room);
        System.out.println(one);
    }

    @GetMapping("/test")
    public void test() {
        throw  new BusinessException("测试异常");
    }

    @GetMapping("/start")
    public String start(){
        return "开始发牌:"+port;
    }

    public String channel() throws IOException {
        FileInputStream fileInputStream = new FileInputStream("");
        FileChannel channel = fileInputStream.getChannel();
        ByteBuffer  buffer = ByteBuffer.allocate(1024);
        int read = channel.read(buffer);
        while (read != -1){
            buffer.flip();
            while (buffer.hasRemaining()){
                System.out.print((char) buffer.get());
            }
            buffer.clear();
        }

        return "channel";
    }
}
